package com.hxkj.controller;

import com.github.pagehelper.PageInfo;
import com.hxkj.domain.po.SysUser;
import com.hxkj.service.UserManagementService;
import com.platform.common.domain.result.ParameterDataStruct;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.Callable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@RestController
@RequestMapping(value = "/userManagement")
public class UserManagementController {

    @Autowired
    private UserManagementService userManagementService;
    @Value("${storage.imgUrl}")
    private String imgUrl;

    @RequestMapping(value = "/getList")
    public Callable<PageInfo<SysUser>> getList(@RequestBody ParameterDataStruct<SysUser> parameterDataStruct) throws Exception{
        return () -> userManagementService.getList(parameterDataStruct.getData()==null?new SysUser():parameterDataStruct.getData(),
                parameterDataStruct.getPageTo());
    }

    /*@RequestMapping(value = "/getList", method = RequestMethod.POST)
    public Callable<PageInfo<SysUser>> getList(@ModelAttribute SysUser user, PageTo pageParams) throws Exception{
        return () -> userManagementService.getList(user , pageParams);
    }*/

    @RequestMapping(value = "/getUser", method = RequestMethod.POST)
    public Callable<ResultDataStruct<SysUser>> getUser(@RequestBody SysUser sysUser) throws Exception{
        return () -> userManagementService.getUser(sysUser);
    }

    @RequestMapping(value = "/modifyUserStatus", method = RequestMethod.POST)
    public Callable<ResultMessageStruct> modifyUserStatus(@RequestBody SysUser sysUser) throws Exception{
        return () -> userManagementService.modifyUserStatus(sysUser);
    }

    @RequestMapping(value = "/selectAllUserId", method = RequestMethod.POST)
    public Callable<ResultDataStruct<List<SysUser>>> selectAllUserId() throws Exception{
        return () -> userManagementService.selectAllUserId();
    }

    @RequestMapping(value = "/selectUserByAccount", method = RequestMethod.POST)
    public Callable<ResultDataStruct<SysUser>> selectUserByAccount(@RequestBody SysUser sysUser) throws Exception{
        return () -> userManagementService.selectUserByAccount(sysUser);
    }

    @RequestMapping(value = "/modifyUser", method = RequestMethod.POST)
    public Callable<ResultMessageStruct> modifyUser(@RequestBody SysUser sysUser) throws Exception{
        return () -> userManagementService.modifyUser(sysUser);
    }
}
